package com.ts.controller.achievement;

import com.ts.dto.ScientificResearchProjectDTO;
import com.ts.result.Result;
import com.ts.service.achievement.ScientificResearchProjectService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 科研项目相关接口
 */
@RestController
@RequestMapping("/achievement/scientificResearchProject")
@Tag(name = "科研项目相关接口", description = "科研项目的提交和查询功能")
@Slf4j
public class ScientificResearchProjectController {

    @Autowired
    private ScientificResearchProjectService scientificResearchProjectService;

    /**
     * 提交一个科研项目成果
     * @param scientificResearchProjectDTO
     * @return
     */
    @Operation(summary = "提交", description = "提交科研项目成果")
    @PostMapping()
    public Result saveScientificResearchProject(@RequestBody ScientificResearchProjectDTO scientificResearchProjectDTO) {
        log.info("scientificResearchProjectDTO:{}", scientificResearchProjectDTO);
        scientificResearchProjectService.save(scientificResearchProjectDTO);
        return Result.success();
    }

    /**
     * 根据ID查询
     * @param id
     * @return
     */
    @Operation(summary = "根据ID查询", description = "根据ID查询科研项目详情")
    @GetMapping("/{id}")
    public Result<ScientificResearchProjectDTO> getById(@PathVariable Long id) {
        log.info("查询科研项目ID: {}", id);
        ScientificResearchProjectDTO projectDTO = scientificResearchProjectService.getById(id);
        return Result.success(projectDTO);
    }

    /**
     * 动态更新科研项目
     * @param scientificResearchProjectDTO
     * @return
     */
    @Operation(summary = "更新", description = "更新科研项目")
    @PutMapping()
    public Result updateScientificResearchProject(@RequestBody ScientificResearchProjectDTO scientificResearchProjectDTO) {
        log.info("更新科研项目: {}", scientificResearchProjectDTO);
        scientificResearchProjectService.update(scientificResearchProjectDTO);
        return Result.success();
    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @Operation(summary = "删除", description = "根据ID删除科研项目")
    @DeleteMapping("/{id}")
    public Result deleteScientificResearchProject(@PathVariable Long id) {
        log.info("删除科研项目ID: {}", id);
        scientificResearchProjectService.delete(id);
        return Result.success();
    }
}